package com.worldcup.model.dto;

import com.worldcup.model.Country;
import com.worldcup.model.PredictKnockout;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;

/**
 * @author duwan.zq
 * @date 2018/05/26
 */
@Getter
@Setter
@NoArgsConstructor
public class PredictKnockoutDTO implements Serializable{

    @NotBlank
    private Integer gameId;

    @NotBlank
    private Integer homeCountryId;

    private String homeCountryName;

    private String homeCountryImg;

    @NotBlank
    private Integer awayCountryId;

    private String awayCountryName;

    private String awayCountryImg;

    @NotBlank
    private Integer winCountryCode;


    public PredictKnockoutDTO(PredictKnockout predictKnockout, Country homeCountry, Country awayCountry) {
        this.gameId = predictKnockout.getMatchCode();
        this.homeCountryId = homeCountry.getId();
        this.homeCountryName = homeCountry.getName();
        this.homeCountryImg = homeCountry.getImgUrl();
        this.awayCountryId = awayCountry.getId();
        this.awayCountryName = awayCountry.getName();
        this.awayCountryImg = awayCountry.getImgUrl();
        this.winCountryCode = predictKnockout.getWinCountryId();
    }

    public PredictKnockout toPredictKnockout(String openid, Integer matchType) {
        PredictKnockout predictKnockout = new PredictKnockout();
        predictKnockout.setOpenid(openid);
        predictKnockout.setMatchType(matchType);
        predictKnockout.setHomeCountryId(this.homeCountryId);
        predictKnockout.setAwayCountryId(this.awayCountryId);
        predictKnockout.setMatchCode(this.gameId);
        predictKnockout.setWinCountryId(this.winCountryCode);
        return predictKnockout;
    }

    @Override
    public String toString() {
        return super.toString();
    }


}
